package com.example.rwq_test.leetcode;

/**
 * TODO note
 *
 * @author renweiqiang
 * @version 1.0.0
 * @createTime 2023/11/17
 */
public class TwoStringMulti {
    public static String multi(String s1, String s2) {
        int length = s1.length() + s2.length();
        int[] arr = new int[length];
        for (int i = s1.length() - 1; i >= 0; i--) {
            for (int j = s2.length() - 1; j >= 0; j--) {
                int a = s1.charAt(i) - '0';
                int b = s2.charAt(j) - '0';
                int n = i + j + 1;
                int mul = arr[n] + a * b;
                arr[n] = mul % 10;
                int up = arr[n - 1] + mul / 10;
                arr[n - 1] = up % 10;
                arr[n - 2] = arr[n - 2] + up / 10;
            }
        }
        String result = "";
        for (int i = 0; i < arr.length; i++) {
            if (i == 0 && arr[i] == 0) {
                continue;
            }
            result = result + arr[i];
        }
        return result;
    }

    public static void main(String[] args) {
        System.out.println(multi("123", "456"));
    }
}
